#ifndef PROCEDUREWIDGET_H
#define PROCEDUREWIDGET_H

#include <QWidget>
#include "procedure_global.h"
#include "procedureinterface.h"
class QThread;
class ImageEnhanceThread;

namespace Ui {
class ProcedureWidget;
}

class ProcedureWidget : public QWidget, public ProcedureInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID ProcedurePlugin_iid)
    Q_INTERFACES(ProcedureInterface)
public:
    explicit ProcedureWidget(QWidget *parent = 0);
    ~ProcedureWidget();

    QObject *getObject() { return this; }
    void setProcedureHook(ProcedureProc proc, void *userData) { m_proc = proc, m_userData = userData; }
    void setImage(ushort *img, int width, int height, int bits);
    ushort *getEnhancedImage(ushort *&img, int &width, int &height);
    bool getBodyPartAndViewPos(QString &part, QString &pos);
    bool setDoseValues(const double &kv, const double &ma, const double &ms, const double &mx);
    bool getDoseValues(double &kv, double &ma, double &ms, double &mx) const;
    bool getWindow(double &center, double width) const;
    bool setWindow(const double &center, const double &width);
    bool getClipRect(QRect &rect) const;
    bool setClipRect(const QRect &rect);
    bool getTransform(bool &rl, bool &rr, bool &fh, bool &fv) const;


private slots:
    void onImageEnhanced(int ret, const QString &err);
    void onBodyPartChanged(const QString &part);
    void onExamChanged();
    void onVPosChanged();

private:
    void init();
    QString getCurExam() const;
    QString getCurVPos() const;
    QString getConfigFile(const QStringList &filters) const;

    Ui::ProcedureWidget *ui;
    ImageEnhanceThread *iet;

    ushort *ieImg;
    int ieWidth;
    int ieHeight;

    ProcedureProc m_proc;
    void *m_userData;
};

#endif // PROCEDUREWIDGET_H
